package com.toby.ioc.processor;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.stereotype.Component;

/**
 * @desc: bean工厂的后置处理器 触发时机 bean定义注册之后 bean实例化之前
 * @author: toby
 * @date: 2019/7/21 23:04
 */
@Component
public class TobyBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        System.out.println("调用了TobyBeanFactoryPostProcessor的postProcessBeanFactory方法");
        for(String beanName : beanFactory.getBeanDefinitionNames()){
            if("tobyBean".equals(beanName)){
                BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
                beanDefinition.setLazyInit(true);
            }
        }
    }
}
